<?php
    include_once("../action/checkAuthenticationAction.php");
    include_once("../service/articleService.php");
    include_once("../util/constant.php");
    include_once("../util/message.php");
    
    include_once("../util/authUtil.php");
    $perm_array = $_SESSION["permissions"];
?>
<!DOCTYPE html>
<html lang="en">
<head>
	<title>Quản lí trang tin tức</title>
	<?php include("import-css.php");?>	
</head>
<body>
	<?php include("header.php");?>
    
    <div class="container-fluid">
		<div class="row-fluid">
            <!--Menu-->
            <?php include("menu.php");?>
            <!--Content-->
            <div class="box span10 offset2">
    					<div class="box-header well" data-original-title>
                        <?php
                            $require_perm = array("create article");
                            if(authUtil($require_perm,$perm_array,true)){
                        ?>
        						<a class="btn btn-primary" href="./article-detail.php?action=<?php echo NEW_ACTION; ?>">
                                    <i class="icon-edit icon-white"></i>Thêm mới
                                </a>
                        <?php
                            }
                        ?>
    						<div class="box-icon">
    							<a href="#" class="btn btn-setting btn-round"><i class="icon-cog"></i></a>
    							<a href="#" class="btn btn-minimize btn-round"><i class="icon-chevron-up"></i></a>
    						</div>
    					</div>
    					<div class="box-content">
    						<table class="table table-striped table-bordered bootstrap-datatable datatable">
    						  <thead>
    							  <tr>
    								  <th>Tiêu đề</th>
                                      <th>Thuộc nhóm</th>
                                      <th>Ngày tạo</th>
                                      <th>Chức năng</th>
    							  </tr>
    						  </thead>   
    						  <tbody>
                                <?php
                                    $articles = getAllArticle();
                                    while($article = mysql_fetch_array($articles)){
                                ?>
								<tr>
                                    <td class="center"><?php echo $article["ART_TITLE"]; ?></td>
                                    <td class="center"><?php echo $article["PAG_NAME"]; ?></td>
                                    <td class="center"><?php $creation_date = new DateTime($article["ART_CREATIONDATE"]); echo $creation_date->format('H:i d/m/Y '); ?></td>
                                    <td>
                                    <?php
                                        $require_perm = array("edit article","create article");
                                        if(authUtil($require_perm,$perm_array,false)){
                                    ?>
                                        <a class="btn btn-info" href="./article-detail.php?action=<?php echo EDIT_ACTION; ?>&id=<?php echo $article['ART_ID']; ?>">
                                            <i class="icon-edit icon-white"></i>  
                                            Cập nhật
                                        </a>
                                    <?php
                                        }
                                    ?>
                                        <?php
                                                $require_perm = array("delete article");
                                                if(authUtil($require_perm,$perm_array,true)){
                                        ?>
                                        <a class="btn btn-danger" href="../action/deleteArticle.php?id=<?php echo $article["ART_ID"]; ?>">
                                            <i class="icon-trash icon-white"></i> 
                                            Xóa
                                        </a>
                                        <?php
                                            }
                                        ?>
                                    </td>
                                </tr>
                                <?php
                                    }
                                ?>
    						  </tbody>
    					  </table>            
                        </div>
            </div><!--/span-->
        </div>
    </div>

    <?php include("footer.php");?>
		
	</div><!--/.fluid-container-->

	<?php include("import-js.php");?>	
    
</body>
</html>
